package com.hopu.v1.controller.admin.verify;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopu.v1.pojo.common.PageData;
import com.hopu.v1.pojo.common.R;
import com.hopu.v1.pojo.question.Questions;
import com.hopu.v1.pojo.question.QuestionsBanks;
import com.hopu.v1.service.admin.verify.VerifyQuestionsBanksService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 题库表，存储题库相关信息(QuestionsBanks)表控制层
 *
 * @author makejava
 * @since 2024-09-30 14:41:12
 */
@CrossOrigin
@RestController
@RequestMapping("/api/v1/admin/verify/questionsBanks")
public class VerifyQuestionsBanksController {
    /**
     * 服务对象
     */
    @Resource
    private VerifyQuestionsBanksService questionsBanksService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param questionsBanks 查询实体
     * @return 所有数据
     */
    @GetMapping
    public R selectAll(Page<QuestionsBanks> page, QuestionsBanks questionsBanks) {
        return R.ok(this.questionsBanksService.page(page, new QueryWrapper<>(questionsBanks)));
    }

    /**
     * 分页显示所有数据
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/selectAll")
    public R selectAll(Integer currentPage, Integer pageSize) {
        PageData<QuestionsBanks> subjectPageData = questionsBanksService.selectAll(currentPage, pageSize);
        return R.ok("数据获取成功",subjectPageData);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id) {
        return R.ok(this.questionsBanksService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param questionsBanks 实体对象
     * @return 新增结果
     */
    @PostMapping
    public R insert(@RequestBody QuestionsBanks questionsBanks) {
        return R.ok(this.questionsBanksService.save(questionsBanks));
    }

    /**
     * 修改数据
     *
     * @param questionsBanks 实体对象
     * @return 修改结果
     */
    @PutMapping
    public R update(@RequestBody QuestionsBanks questionsBanks) {
        return R.ok(this.questionsBanksService.updateById(questionsBanks));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Long> idList) {
        return R.ok(this.questionsBanksService.removeByIds(idList));
    }
}

